Skip to main content

Log to Console

Description

The log_to_console function logs messages to the console with the current UTC time and an optional agent name.

Function Signature:

def log_to_console(message: str, agent_name: str = '') -> None:

Parameters

  • message (str): The message to log to the console.
  • agent_name (str, default = ''): The name of the agent (optional).

Returns

  • None

Example Usage

log_to_console('System started successfully', 'AgentX')

Example Output:

[2025-04-09 10:00:00 UTC]: [AgentX]: System started successfully

Notes

  • This function formats the current UTC time and optionally includes the agent name to format a detailed log message.
  • The datetime and pytz libraries are used to retrieve and format the UTC time.
  • The result is printed to the console, which can be redirected to a file or other output as needed.